package com.guagua.system.service;

import com.guagua.system.entity.UploadConfig;
import com.guagua.system.strategy.UploadStrategy;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.Map;

@Service
public class UploadService {
    private final Map<String, UploadStrategy> strategyMap;
    private final UploadConfig config;
    
    public UploadService(Map<String, UploadStrategy> strategyMap, UploadConfig config) {
        this.strategyMap = strategyMap;
        this.config = config;
    }
    
    public String upload(MultipartFile file) {
        UploadStrategy strategy = strategyMap.get(config.getStorageType());
        if (strategy == null) {
            throw new RuntimeException("未找到对应的上传策略");
        }
        return strategy.upload(file);
    }
    
    public void delete(String fileUrl) {
        UploadStrategy strategy = strategyMap.get(config.getStorageType());
        if (strategy == null) {
            throw new RuntimeException("未找到对应的上传策略");
        }
        strategy.delete(fileUrl);
    }
} 